package com.hwd.gmall.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.hwd.gmall.product.feign.ProductIndexFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 前端首页的控制层
 *
 * @author 黄伟东/Victor
 * @date 2022/4/26 16:41
 */
@Controller
@RequestMapping(value = "/page/index")
public class IndexController {

    @Autowired
    private ProductIndexFeignClient productIndexFeignClient;

    @GetMapping
    public String index(Model model) {
        // 远程调用查询首页分类信息
        List<JSONObject> indexCategory = productIndexFeignClient.getIndexCategory();
        // 把首页分类信息存到模板对象中
        model.addAttribute("categoryList", indexCategory);
        // 打开首页
        return "index";
    }
}
